#!/bin/bash

# 定义变量
CONTAINER_NAME="tz-file"
IMAGE_NAME="file"
DOCKERFILE_PATH="." # Dockerfile所在的目录
CONFIG_VOLUME_PATH="/data/logs:/data/logs" # 配置文件映射路径，追加IMAGE_NAME
PORT="8903"

# 停止并删除现有的容器
echo "Stopping and removing existing container..."
docker stop "$CONTAINER_NAME" 2>/dev/null
docker rm "$CONTAINER_NAME" 2>/dev/null

# 构建新的镜像
echo "Building new Docker image..."
docker build -t "$IMAGE_NAME" "$DOCKERFILE_PATH"

# 启动新的容器
echo "Starting new container..."
docker run -d --name "$CONTAINER_NAME" \
 --network=host \
 -v "$CONFIG_VOLUME_PATH" \
 -p "$PORT:$PORT" \
 "$IMAGE_NAME"

echo "Done!"
